use criterion::{criterion_group, criterion_main, Criterion};
use tinyexpr::tinyexpr::*;

fn tinyexpr_te_interp_benchmark(c: &mut Criterion) {
    c.bench_function("tinyexpr_te_interp", |b| {
        b.iter(|| te_interp("3 + 4 * 2 / (1 - 5)^2"))
    });
}

fn tinyexpr_te_compile_benchmark(c: &mut Criterion) {
    c.bench_function("tinyexpr_te_compile", |b| {
        b.iter(|| te_compile("3 + 4 * 2 / (1 - 5)^2", &[]))
    });
}

fn tinyexpr_expr_eval_benchmark(c: &mut Criterion) {
    let expr = te_compile("3 + 4 * 2 / (1 - 5)^2", &[]).unwrap();
    c.bench_function("tinyexpr_expr_eval", |b| {
        b.iter(|| expr.borrow().eval())
    });
}

fn tinyexpr_expr_optimize_benchmark(c: &mut Criterion) {
    let expr = te_compile("3 + 4 * 2 / (1 - 5)^2", &[]).unwrap();
    c.bench_function("tinyexpr_expr_optimize", |b| {
        b.iter(|| expr.borrow_mut().optimize())
    });
}

criterion_group!(
    benches,
    tinyexpr_te_interp_benchmark,
    tinyexpr_te_compile_benchmark,
    tinyexpr_expr_eval_benchmark,
    tinyexpr_expr_optimize_benchmark
);
criterion_main!(benches);